package edu.uta.ui;
/**
 * @author Anvitha Banakal Sadananda
 * @author   Manasa
 * 
 * reference http://gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity
 * 			 http://androidgenuine.com/?tag=tabactivity-nested-activity
 * 
 */
import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;


public class ZipActivity extends ActivityGroup 
{

	public static ZipActivity group;
	private ArrayList<View> history;



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.history = new ArrayList<View>();
		group = this;

		View view = getLocalActivityManager().startActivity("ListView", new
				Intent(this,ZipCode2.class)
		.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
		.getDecorView();
		replaceView(view);
	}

	public void replaceView(View v) {
		history.add(v);
		setContentView(v);
	}

	public void back()
	{
		if(history.size() > 0) {
			//System.out.println("history.size()1st ::"+history.size());
			history.remove(history.size()-1);

			if((history.size()-1)>=0 && history.size()!=1){

			//	System.out.println("history.size() 2nd ::"+history.size());
				setContentView(history.get(history.size()-1));

			}
			else if(history.size()==1)
			{
				//System.out.println("history.size()3rd ::"+history.size());
				View view = getLocalActivityManager().startActivity("ListView", new
						Intent(this,ZipCode2.class)
				.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
				.getDecorView();
				setContentView(view);	
			}
			else finish();
		}else {
			finish();
		}
	}

	@Override
	public void onBackPressed() {
		ZipActivity.group.back();
		return;
	}

	



}